#! /usr/bin/env runhugs +l
--
-- Copyright (C) 2017 wang <wang@Yet-Another-MBP>
--
-- Distributed under terms of the MIT license.
--

-- 01
myLast :: [t] -> t
myLast []     = error "empty list"
myLast (x:[]) = x
myLast (_:xs) = myLast xs


-- 02
myButLast :: [t] -> t
myButLast = (!! 1) . reverse

-- 03
elementAt :: [t] -> Int -> t
elementAt xs i = xs !! (i - 1)
